document.getElementById("loginForm").addEventListener("submit", function (e) {
  e.preventDefault();
  const data = {
    username: document.getElementById("username").value,
    password: document.getElementById("password").value,
  };

  axios
    .post("http://localhost:4407/api/User/login", data)
    .then((response) => {
      const data = response.data;
      if (data.msg === "成功") {
        localStorage.setItem("token", data.token);
        window.location.href = "Gameindex.html";
      } else {
        alert("登录失败: " + data.msg);
      }
    })
    .catch((error) => console.error("Error:", error));
});
